package com.example.concurrent.AtomicInteger;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by SOAL on 2017/2/11 0011.
 */
public class AtomicIntegerDemo {
    public static void main(String[] args) {
        //AtomicInteger atomicInteger = new AtomicInteger();

        AtomicInteger atomicInteger = new AtomicInteger(124);

        int theValue = atomicInteger.get();
        System.out.println(theValue);

//        atomicInteger.set(234);
//        System.out.println(atomicInteger.get());

        //如果相等，将 AtomicInteger 的值更新为 234
//        int expectedValue = 123;
//        int newValue      = 234;
//        boolean comp1=atomicInteger.compareAndSet(expectedValue, newValue);
//        System.out.println(comp1);
//        System.out.println(atomicInteger.get());


        System.out.println(atomicInteger.getAndAdd(10));//返回的是增加以前的 AtomicInteger 的值
        System.out.println(atomicInteger.addAndGet(10));//返回加操作之后的值

//        decrementAndGet()
//        getAndDecrement()

    }
}
